package com.project.webpage.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.project.webpage.dto.SkbDailyDto;
import com.project.webpage.dto.SkbDetailDto;
import com.project.webpage.dto.SkbDto;
import com.project.webpage.dto.SkbParam;
import com.project.webpage.entity.Skb;
import com.project.webpage.mapper.SkbMapper;
import com.project.webpage.service.SkbService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SkbServiceImpl implements SkbService {

    @Resource
    private SkbMapper skbMapper;

    @Override
    @DS("master")
    public List<SkbDto> getListForPage(SkbParam param) {
        return skbMapper.selectListByUid(param);
    }

    @Override
    @DS("master")
    public List<SkbDailyDto> getById(SkbParam param) {
        return skbMapper.selectById(param);
    }

    @Override
    @DS("master")
    public List<SkbDetailDto> getBcListById(SkbParam param) {
        return skbMapper.selectBcListById(param);
    }

    @Override
    @DS("master")
    public Integer getCountById(Long id) {
        Example example = new Example(Skb.class);
        Example.Criteria c = example.createCriteria();
        c.andEqualTo("id", id);
        return skbMapper.selectCountByExample(example);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void updateStateById(SkbParam param) {
        skbMapper.updateStateById(param);
    }
}
